(*--------------------------------------------------------
    Holt                  http://coderesearchlabs.com/holt
    by Javier Santo Domingo (j-a-s-d@coderesearchlabs.com)
  --------------------------------------------------------
    reporting
  --------------------------------------------------------*)

unit holt_reporting;

{$I holt_defines.inc}

interface

uses
  holt_architecture,
  holt_types;

function NewReportBuilder: IhReportBuilder;

implementation

uses
  holt_consts;

{ ThReportBuilder }

type
  ThReportBuilder = class(TInterfacedObject, IhReportBuilder)
  strict protected
    function AsPrompt(const APath: gString): gString; inline;
    function AsError(const AMessage: gString = ''): gString; inline;
    function AsMultiline(const ATitle, ABody: gString): gString; inline;
    function AsLine(const ATitle, ABody: gString): gString; inline;
    function AsKindsForLevel(AEmitter: IhEmitter; ALevel: gNumber): gString; inline;
  end;

function ThReportBuilder.AsPrompt(const APath: gString): gString;
begin
  result := APath + MSG_PROMPT + ' ';
end;

function ThReportBuilder.AsError(const AMessage: gString = ''): gString;
begin
  result := MSG_ERROR;
  if AMessage <> '' then
    result += ': ' + AMessage;
end;

function ThReportBuilder.AsMultiline(const ATitle, ABody: gString): gString;
begin
  result := ATitle + LineEnding + SEPARATOR + LineEnding + ABody;
end;

function ThReportBuilder.AsLine(const ATitle, ABody: gString): gString;
begin
  result := ATitle + '=' + ABody;
end;

function ThReportBuilder.AsKindsForLevel(AEmitter: IhEmitter; ALevel: gNumber): gString;
begin
  if assigned(AEmitter) then
    result := AsLine(MSG_KINDS, AEmitter.GetLevelKinds(ALevel) + LineEnding)
  else
    result := '';
end;

function NewReportBuilder: IhReportBuilder;
begin
  result := ThReportBuilder.Create;
end;

end.
